<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
</head>
<body>
<div id="example">
    <hr>
    <h1>订单编号<span class="out_trade_no">{{$model['order_no']}}</span>:</h1>
    <hr>
<img src="{{$goods['pic']}}">
    <hr>
<div>商品: <span class="subject">{{$goods['goods_name']}}</span></div>
    <hr>
<div>付款<span class="total_amount">{{$model['real_price']}}</span></div>
    <hr>
<div>实际付款<span>{{$model['real_price']}}</span></div>
    <hr>
@if($model['type'] == 2 && $model['status'] == 3)
     <button class="sub" @click="pay">立即支付</button>
@elseif($model['type'] == 2 && $model['status'] == 1)
    <button class="sub" @click="pay">请支付尾款</button> <span class="red">@{{minutes}}分@{{seconds}}秒</span>
@endif
</div>
</body>
</html>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>

    var vm = new Vue({
        el: '#example',
        data() {
            return {
                minutes: 0, //分
                seconds: 59, //秒
            }
        } ,
        mounted(){
                var  out_trade_no= $(".out_trade_no").text();
                var _this = this;
                var time = setInterval(function() {
                    if (_this.seconds === 0 && _this.minutes !== 0) {
                        _this.seconds = 59;
                        _this.minutes -= 1;
                    } else if (_this.minutes === 0 && _this.seconds === 0) {
                        _this.seconds = 0;
                        axios
                            .get('/passtime?out_trade_no='+out_trade_no)
                            .then(response => (this.info = response))
                            .catch(function (error) { // 请求失败处理
                                console.log(error);
                            });
                        window.clearInterval(time);
                    } else {
                        _this.seconds -= 1;
                    }
                }, 1000);
        },
        methods:{
            pay(){
                var  out_trade_no= $(".out_trade_no").text();
                var total_amount=$(".total_amount").text();
                var subject=$(".subject").text();
                window.location.href="/pay?out_trade_no="+out_trade_no+"&total_amount="+total_amount+"&subject="+subject
            }
        }
    })
</script>
